import { reactive } from "vue";
import { defineStore } from "pinia";
import { getUserInfoInfo as getUserInfo } from "@/utils/api/master";
import type { IMyInfo } from "@/types/master";

/* 组合式的写法 */
export const useUserStore = defineStore("user", () => {
  const userInfo = reactive<IMyInfo>({
    agency_name: "",
    role_name: "",
    user_name: "",
    nick_name: "",
    mobile: "",
    avatar: ""
  });
  /* 获取用户信息 */
  function getUserInfoInfo<IMyInfo>() {
    return getUserInfo<IMyInfo>();
  }
  /* 修改用户信息 */
  function setUserInfo(data: IMyInfo) {
    userInfo.agency_name = data.agency_name;
    userInfo.role_name = data.role_name;
    userInfo.user_name = data.user_name;
    userInfo.nick_name = data.nick_name;
    userInfo.mobile = data.mobile;
    userInfo.avatar = data.avatar;
  }
  return { userInfo, getUserInfoInfo, setUserInfo };
});
